#!usr/bin/perl -w
=head1 Version
Author: Zeng Liang,zlnineday@gmail.com
Date: 2014-08-04
=head1 Usage
perl rna_compare_analy.pl pro.fa.list [options]
-list                  <str>       input the sample nucleic list (fa format list)
-method                <str>       the method for construct evolation tree,nj ml bayes
-qsub                  <qsub>      whether qsub or not;default yes 
-help                              output help information to screen
=head1 Exmple
perl rna_compare_analy.pl pro.fa.list
pro.fa.list
name1   name1.pro.fa
name2   name2.pro.fa
...
=cut
use strict;
use Getopt::Long;
use FindBin qw($Bin $Script);
my ($list, $help, $qsub, $method);my ($shell, $result, $ref_index);
GetOptions(
    "list:s"=>\$list,
    "method:s"=>\$method,
    "qsub:s"=>\$qsub,
    "help"=>\$help
);
$qsub   ||="no";$method   ||="nj";

die `pod2text $0` if (@ARGV < 1 || $help);
open A,$ARGV[0];my @samp;
while(<A>){
    chomp;my @a=split;my @b=split /\//,$a[-1];
    my $id=$a[0].".pep.fa";
    `ln -s $a[1]`;
    `mv $b[-1] $a[0].pep.fa`;
    push @samp,$id;

}
close A;

my $sam=join ",",@samp;
if($qsub eq "yes"){
    print "#PBS -l nodes=1:ppn=8\n#PBS -q public01\ncd \$PBS_O_WORKDIR\n";
}
print "$sam\n";
`perl /mnt/lustre/users/zengl/software/ORTHOMCLV1.4/orthomcl.pl --mode 1 --fa_files $sam >ortho.log.txt 2>ortho.log.txt`;
open IN,"ortho.log.txt";
while(<IN>){
    chomp;my @a=split;
    if(/Final ORTHOMCL Result: /){
        `cp $a[3] ./`;
    }
}
close IN;
`perl /mnt/lustre/users/zengl/bin/rna_analysis_pipeline/compara/select_ortholog_gene_pro.pl $ARGV[0] all_orthomcl.out`;
`perl /mnt/lustre/users/zengl/bin/rna_analysis_pipeline/compara/deal_with_muscle_out_step2.pl $ARGV[0] muscle.out.list`;
if($method == "bayes"){
    print "perl /mnt/lustre/users/zengl/bin/rna_analysis_pipeline/compara/phylo_tree.pl input.phy -type $method -data dna";
}
else{
    print "perl /mnt/lustre/users/zengl/bin/rna_analysis_pipeline/compara/phylo_tree.pl input.phy -type $method -d nt";
}
